package com.sixth.other;

import com.sixth.bean.MarketSystem;
import com.sixth.bean.vo.ConfigMallVO;
import lombok.Data;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author ljh
 * @version 1.0
 * @describition:
 * 这是一个其他类，请不要修改
 * @since 2022/9/7 22:47
 **/
@Data
public class MarketConfig {
    //market_mall_longitude":id=13
    //"market_mall_latitude":id=3
    //"market_mall_address":id=16
    //"market_mall_qq":id=9
    //""market_mall_phone"":id = 14
    //"market_mall_name":id = 7
    public static List<String> list;
    public static final String marketMallLongitude = "market_mall_longitude";
    public static final String marketMallLatitude = "market_mall_latitude";
    public static final String marketMallAddress = "market_mall_address";
    public static final String marketMallQq = "market_mall_qq";
    public static final String marketMallPhone = "market_mall_phone";
    public static final String marketMallName = "market_mall_name";

    static {
        list = new ArrayList<>();
        list.add(marketMallLongitude);
        list.add(marketMallLatitude);
        list.add(marketMallAddress);
        list.add(marketMallQq);
        list.add(marketMallPhone);
        list.add(marketMallName);
    }

    public static ConfigMallVO getConfigMall(List<MarketSystem> marketSystems){
        ConfigMallVO configMallVO = new ConfigMallVO();
        for (MarketSystem marketSystem : marketSystems) {
            if(marketMallLongitude.equals(marketSystem.getKeyName())){
                configMallVO.setMarket_mall_longitude(marketSystem.getKeyValue());
            }
            if(marketMallLatitude.equals(marketSystem.getKeyName())){
                configMallVO.setMarket_mall_latitude(marketSystem.getKeyValue());
            }
            if(marketMallAddress.equals(marketSystem.getKeyName())){
                configMallVO.setMarket_mall_address(marketSystem.getKeyValue());
            }
            if(marketMallQq.equals(marketSystem.getKeyName())){
                configMallVO.setMarket_mall_qq(marketSystem.getKeyValue());
            }
            if(marketMallPhone.equals(marketSystem.getKeyName())){
                configMallVO.setMarket_mall_phone(marketSystem.getKeyValue());
            }
            if(marketMallName.equals(marketSystem.getKeyName())){
                configMallVO.setMarket_mall_name(marketSystem.getKeyValue());
            }
        }
        return configMallVO;
    }

    public static ConfigMallVO getConfigMall(Map<String, Object> map){
        ConfigMallVO configMallVO = new ConfigMallVO();
        Class<? extends ConfigMallVO> clazz = configMallVO.getClass();
        for (String s : list) {
            String value = (String) map.get(s);
            Field declaredField = null;
            try {
                declaredField = clazz.getDeclaredField(s);
                declaredField.setAccessible(true);
                declaredField.set(configMallVO,value);
            } catch (NoSuchFieldException | IllegalAccessException e) {
                e.printStackTrace();
            }

        }
        return configMallVO;
    }


}
